#include "stdafx.h"
#include "core/system.h"
#include "util/make_unique.h"

namespace natrium {
	namespace core {
		System::System(const std::string& name, unsigned int taskFlags):
			util::UniqueNamed(name),
			mSettings(name),
			mTaskFlags(taskFlags)
		{
		}

		System::~System() {
		}

		bool System::init() {
			mChan.broadcast(SystemInitializing(this));

			if (mTaskFlags != Task::NONE)
				mUpdater = std::make_shared<SystemUpdater>(this, mTaskFlags);

			return true;
		}

		void System::update() {
		}

		void System::shutdown() {
			mChan.broadcast(SystemShuttingDown(this));
		}

		System::SystemInitializing::SystemInitializing(System* s): 
			mSystem(s)
		{
		}

		System::SystemShuttingDown::SystemShuttingDown(System* s): 
			mSystem(s)
		{
		}

		System::SystemUpdater::SystemUpdater(System* s, unsigned int taskFlags):
			core::Task(taskFlags),
			mSystem(s)
		{
		}

		void System::SystemUpdater::run() {
			mSystem->update();
		}
	}
}